<template>
	<view class="login-wrap">
		<!-- 图标 -->
		<uni-icons type="contact-filled" size="100" color="#afafaf"/>
		<!-- 按钮 -->
		<button type="primary" class="btn-login" open-type="getUserInfo" @getuserinfo="getUserInfo">一键登陆</button>
		<!-- 防文字的盒子 -->
		<view class="tip">
			登录后尽享更多权益
		</view>
	</view>
</template>

<script>
	export default {
		name:"my-login",
		data() {
			return {}
		},
		methods: {
			async getUserInfo(e) {
				this.$store.commit('m_user/setUserInfo', e.detail.userInfo)
				 const res = await uni.login()
				 if (res.errMsg !== 'login:ok') uni.$showToast('登录失败')
				 const { data } = await uni.$http.get('users/wxlogin', {
					 	encryptedData: e.detail.encryptedData,
					 	rawData: e.detail.rawData,
					 	iv: e.detail.iv,
					 	signature:e.detail.signature,
					 	code: res.code
				 })
				 this.$store.commit('m_user/setToken', data.message.token)
			}
		}
	}
</script>

<style lang="scss">
.login-wrap {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	height: 100vh;
	.btn-login {
		background-color: #c00000;
		color: #fff;
		width: 200px;
		height: 40px;
		border-radius: 20px;
		margin: 20px 0;
	}
	.tip { 
		font-size: 12px;
		color: gray;
	}
}
</style>